package org.tim.es.message;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.tim.es.ElasticsearchConstants;
import org.tim.common.msg.MsgType;
import org.tim.common.msg.TimMessage;
import org.tim.es.session.UserPrivateSession;

import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
@Document(indexName = UserPrivateMessage.INDEX_NAME, type = "_doc")
public class UserPrivateMessage {
    public static final String INDEX_NAME = ElasticsearchConstants.INDEX_PREFIX + "privatemessage";

    @Id
    @Schema(description = "私聊消息 ID")
    @Field(type = FieldType.Keyword)
    private String id;

    @Schema(description = "发送者 ID")
    @Field(type = FieldType.Keyword)
    private String fromUserId;

    @Schema(description = "发送者名称")
    @Field(type = FieldType.Keyword)
    private String fromUserName;

    @Schema(description = "接收者 ID")
    @Field(type = FieldType.Keyword)
    private String toUserId;

    @Schema(description = "接收者名称")
    @Field(type = FieldType.Keyword)
    private String toUserName;

    @Schema(description = "当前消息会话 ID")
    @Field(type = FieldType.Keyword)
    private String sessionId;

    @Schema(description = "消息类型")
    @Field(type = FieldType.Keyword)
    private MsgType msgType;

    @Schema(description = "消息内容")
    @Field(type = FieldType.Text)
    private Object msgContent;

    @Schema(description = "消息")
    @Field(type = FieldType.Auto)
    private TimMessage timMessage;

    @Schema(description = "消息是否送达")
    @Field(type = FieldType.Boolean)
    private boolean ack = Boolean.FALSE;

    @Schema(description = "消息是否已读")
    @Field(type = FieldType.Boolean)
    private boolean read = Boolean.FALSE;

    @Schema(description = "消息已读时间")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    private LocalDateTime readAt;

    @Schema(description = "消息送到时间")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    private LocalDateTime ackAt;

    @Schema(description = "消息发送时间")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    private LocalDateTime sendAt;
}

